<?php
require_once APP . '/application/admincontrollers/AdminAction.php';
/**
 * 后台管理主页
 * @package admin
 */
class JzController extends AdminAction
{
    
	/**
	 * Enter description here...
	 *
	 * @var JzlistModel
	 */
	private $jz;
    public function init()
    {
    	require_once(APP . '/application/models/JzlistModel.php');
    	
        $this->jz = new JzlistModel($this->db);
    }


    /**
     * 加载框架页
     */
    public function addAction()
    {
    	
    }

    /**
     * 发布新闻
     *
     */
    public function doaddAction()
    {
    	$params = $this->getAllParams();
    	
    	$this->jz->add($params);
    	
    	$this->view->msg = '添加成功';
    		
    	$this->view->url = $this->url($this->view->baseUrl, "jz", "add");
    	$this->showmessage();
    }
    
    /**
     * 文章管理
     *
     */
    public function listAction()
    {
    	global $cfg;
    	$nowp = (int) $this->getParam("nowp", 1);
    	$where = $this->getParam("where");
    	if (!empty($where))
    		$_SESSION['jz_where'] = $where;
    	else{
    		if (!empty($_SESSION['jz_where'])){
    			$where = $_SESSION['jz_where'];
    		}
    	}
    	
    	$per_page = 20;
    	
    	$result = $this->jz->fetchAll($nowp, $per_page, $where);
    	
    	$this->view->nowp = $nowp;
        $this->view->list = $result['list'];
        $this->view->page = $result['page'];
    }
    
    public function delAction()
    {
    	$id = (int) $this->getParam("id");
    	$nowp = (int) $this->getParam("nowp");
    	
    	$this->jz->del($id);
    	
    	header("location:" . $this->url($this->view->baseUrl, "jz", "list", "nowp=" . $nowp, "admin"));
    }
    
    public function editAction()
    {
    	$id = (int) $this->getParam("id");
    	$nowp = (int) $this->getParam("nowp");
    	$content = $this->jz->show($id);
    	        
        $this->view->nowp = $nowp;
        $this->view->info = $content;
    }
    
    public function doeditAction()
    {
    	$id = $this->getParam("id");
    	$params = $this->getAllParams();
    	
    	$nowp = $this->getParam("nowp");
    	$this->jz->change($id, $params);
    	
    	$this->view->msg = '编辑成功';
    	$this->view->url = $this->url($this->view->baseUrl, "jz", "list", "nowp=" . $nowp, "admin");
    	$this->showmessage();
    }
    
}